<!DOCTYPE html>
<html lang="en">
	<head>
	<meta charset="utf-8" />
	<title>UI:LListView</title>
	<script type="text/javascript" src="../load_lufylegend.js"></script>
	<script type="text/javascript" src="../load_lufylegend.ui.js"></script>
	</head>
	<body style="margin:0;padding:0;">
			<div id="legend"></div>
<script>
init(1000/60,"legend",800,450,main);
var backLayer, ctrlLayer, listView;
function MyListChildView(i){
	var self = this;
	base(self,LListChildView,[]);
	var rand = Math.random();
	self.graphics.drawRect(1, "#000000", [0, 0, 50, 30],true,rand < 0.33?"#90EE90":(rand < 0.66 ? "#F4A460":"#E6E6FA"));
	var t = new LTextField();
	t.text = i;
	t.x = t.y = 5;
	self.addChild(t);
}
MyListChildView.prototype.onClick = function(event){
	var self = this;
	console.log(event,self.getChildAt(0).text);
};
function main(){
	LMouseEventContainer.set(LMouseEvent.MOUSE_DOWN,true);
	LMouseEventContainer.set(LMouseEvent.MOUSE_UP,true);
	LMouseEventContainer.set(LMouseEvent.MOUSE_MOVE,true);
	LGlobal.setDebug(true);
	ctrlLayer = new LSprite();
	addChild(ctrlLayer);
	backLayer = new LSprite();
	backLayer.x = 200;
	backLayer.y = 50;
	addChild(backLayer);
	ctrlInit();
	listViewInit(LListView.Direction.Horizontal);
}
function listViewInit(arrangement){
	listView = new LListView();
	backLayer.addChild(listView);
	listView.maxPerLine = 6;
	listView.cellWidth = 50;
	listView.cellHeight = 30;
	listView.resize(300,300);
	listView.arrangement = arrangement;
	listView.graphics.drawRect(1, "#00ff00", [0, 0, listView.clipping.width,listView.clipping.height]);
	var list = [];
	for(var i=0;i<100;i++){
		var c = new MyListChildView(i);
		list.push(c);
	}
	listView.updateList(list);
}
function ctrlInit(){
	var layerBack = new LSprite();
	layerBack.graphics.drawRoundRect(1, "#999999", [0, 0, 140, 30, 4], true, "#f5f5f9");
	layerBack.cacheAsBitmap(true);
	var comboBox = new LComboBox(15, null, null, layerBack);
	comboBox.x = 10;
	comboBox.y= 50;
	comboBox.setChild({label:"Horizontal",value:LListView.Direction.Horizontal});
	comboBox.setChild({label:"Vertical",value:LListView.Direction.Vertical});
	ctrlLayer.addChild(comboBox);
	comboBox.addEventListener(LComboBox.ON_CHANGE,function(event){
		var arrangement = event.target.value;
		listView.remove();
		listViewInit(arrangement);
	});
}

</script>
	</body>
</html>
